package com.ccb.lms.dao;

import java.sql.SQLException;
import java.util.List;

import com.ccb.lms.model.Copy;
import com.ccb.lms.util.BasePage;
import com.ibatis.sqlmap.client.SqlMapClient;

public class CopyDAO implements ICopyDAO {
	private SqlMapClient sqlMapClient = null;

	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	public boolean insertCopy(Copy copy) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.insert("copy.insertCopy", copy);
		return true;
	}

	public boolean deleteCopy(Integer copyNO) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.delete("copy.deleteCopy", copyNO);
		return true;
	}

	public boolean updateCopy(Copy copy) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.update("copy.updateCopy", copy);
		return true;
	}

	@SuppressWarnings("unchecked")
	public List<Copy> getAllCopys() throws SQLException {
		// TODO Auto-generated method stub
		return sqlMapClient.queryForList("copy.getAllcopys");
	}

	public Copy getCopyByNO(Integer copyNO) throws SQLException {
		// TODO Auto-generated method stub		
		return (Copy) sqlMapClient.queryForObject("copy.getCopyByNO", copyNO);
	}

	public int getCopyCount() throws SQLException {
		// TODO Auto-generated method stub
		return (Integer) sqlMapClient.queryForObject("copy.recordCount");
	}

	public BasePage getBasePage(int currentPage, int showRecordNum)
			throws SQLException {
		// TODO Auto-generated method stub
		return new BasePage(currentPage, getCopyCount(), showRecordNum);
	}

	@SuppressWarnings("unchecked")
	public List<Copy> getCopyByPage(BasePage basePage) throws SQLException {
		// TODO Auto-generated method stub
		return sqlMapClient.queryForList("copy.getCopyrByPage", basePage);
	}


}
